<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Borrow_auto extends MY_Controller {
		
	function __construct(){
		parent::__construct();
	}

	// 预约发标
	function borrowautopublish(){
		$this->load->model('Borrow_model');
		$data_post['where']['fstatus'] = 0;
		$data_post['where']['auto_verify_time'] = strtotime(date('Y-m-d H:i',time()));
		$data_post['where']['is_check'] = 1;
		$data_post['where']['is_verify'] = 1;
		$data_post['page_size']  = 10;
		$data_post['page_start'] = 0;
		$data_post['select'] 	= 1;
		
		$vdata = $this->Borrow_model->get_borrow_user_list($data_post);
		$borrow_list = $vdata['borrow_list'];
		
		if($borrow_list){
			foreach($borrow_list as $v){
				$borrow = $this->Borrow_model->get_borrow_obj($v['id']);
		  		if($borrow['fstatus'] != 0){
		  			echo "标的ID {$borrow['ID']},该标不处于待审核状态";
		  			return;
		  		}
		  		$data["fstatus"]			= 1;
		  		$data["verify_remark"]		= '审核成功';
		  		$data["verify_time"]		= $data_post['where']['auto_verify_time'];
		  		$data["verify_user"]		= 1;
				$flag = $this->Borrow_model->verify($v['id'], $data);
				if($flag == 1 && $data["fstatus"] == 1){//自动投标
					$this->Borrow_model->auto_tender_borrow($v['id']);
				}
				$index_borrow_list_key = 'rsh_index_borrow_list';
				$this->mycache->delete($index_borrow_list_key);
				$this->load->model('log_model');$this->log_model->add_log('[自动审核][发标]');
				echo $flag;
			}
		}
		echo "borrow_auto_publish over";
	}
	
	
	// 自动还款
	function repay(){
		$this->load->model('System_model');
		$list = $this->System_model->borrow_repay();
		if(count($list) > 0){
			$this->load->model('Borrow_model');
			foreach($list as $obj){
				$data['repayment_id'] 	= $obj['id'];
				$data['user_id'] 		= $obj['user_id'];
				$data['ip'] 			= '127.0.0.1';
				$ret = $this->Borrow_model->repay($data);
				echo $obj['id'].'-'.$obj['user_id'].'='.$ret;
			}
		}
		echo "repay over";
	}
	
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Borrow_auto extends MY_Controller {
    	
	function __construct(){
		parent::__construct();
	}

	// 预约发标
	function borrowautopublish(){
		$this->load->model('Borrow_model');
		$data_post['where']['fstatus'] = 0;
		$data_post['where']['auto_verify_time'] = strtotime(date('Y-m-d H:i',time()));
		$data_post['where']['is_check'] = 1;
		$data_post['where']['is_verify'] = 1;
		$data_post['page_size']  = 10;
		$data_post['page_start'] = 0;
		$data_post['select'] 	= 1;
		
		$vdata = $this->Borrow_model->get_borrow_user_list($data_post);
		$borrow_list = $vdata['borrow_list'];
		
		if($borrow_list){
			foreach($borrow_list as $v){
				$borrow = $this->Borrow_model->get_borrow_obj($v['id']);
		  		if($borrow['fstatus'] != 0){
		  			echo "标的ID {$borrow['ID']},该标不处于待审核状态";
		  			return;
		  		}
		  		$data["fstatus"]			= 1;
		  		$data["verify_remark"]		= '审核成功';
		  		$data["verify_time"]		= $data_post['where']['auto_verify_time'];
		  		$data["verify_user"]		= 1;
				$flag = $this->Borrow_model->verify($v['id'], $data);
				if($flag == 1 && $data["fstatus"] == 1){//自动投标
					$this->Borrow_model->auto_tender_borrow($v['id']);
				}
				$index_borrow_list_key = 'rsh_index_borrow_list';
				$this->mycache->delete($index_borrow_list_key);
				$this->load->model('log_model');$this->log_model->add_log('[自动审核][发标]');
				echo $flag;
			}
		}
		echo "borrow_auto_publish over";
	}
	
	
		// 自动还款
	function repay(){
		$this->load->model('System_model');
		$list = $this->System_model->borrow_repay();
		if(count($list) > 0){
			$this->load->model('Borrow_model');
			foreach($list as $obj){
				$data['repayment_id'] 	= $obj['id'];
				$data['user_id'] 		= $obj['user_id'];
				$data['ip'] 			= '127.0.0.1';
				$ret = $this->Borrow_model->repay($data);
				echo $obj['id'].'-'.$obj['user_id'].'='.$ret;
			}
		}
		echo "repay over";
	}
	
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}